package com.wica.view;

import com.wica.facetube.R;
import com.wica.media.Player;
import com.wica.model.MovieClip;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListTests extends ListActivity{

	private static final String LOG_TAG = "ListTests";


	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, mStrings));
        getListView().setTextFilterEnabled(true);
    }

    private String[] mStrings = {};
    
    
    /** Creates waiting dialog **/
    @Override
    protected Dialog onCreateDialog(int id) {
    	Log.v(LOG_TAG, LOG_TAG+"onCreateDialog(-1) ERROR NO INTERNET");
    	return new AlertDialog.Builder(this)
    	   			.setIcon(R.drawable.stat_sample)
    	       		.setTitle("No Internet connection was found")
    	            .setMessage("You need an internet connection in order to use the application. Try again later.")                
    	            .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
    	            	public void onClick(DialogInterface dialog, int whichButton) {
    	            		finish();  
    	            	}// onclick method
    	            }).create();
    }// onCreateDialog method
	
    
    /** Called when we select a video from the list
     * 	Plays video **/
    protected void onListItemClick(ListView l, View v, int position, long id){
    	// We get movieClip on position "position" from Adapter and we bundle it with intent
    	// Launching the video player
    	Intent i = (new Intent(ListTests.this, Player.class)).setData(Uri.parse(((MovieClip)getListAdapter().getItem(position)).getFormat1()));
    	String url = ((MovieClip)getListAdapter().getItem(position)).getUrl();
    	i.putExtra("URL", "http://www.youtube.com/v/xJUUK8ETFvw");    
    	i.putExtra("URLThumbnail", "http://i.ytimg.com/vi/xJUUK8ETFvw/2.jpg");    	
    	i.putExtra("totalRating", Float.valueOf("3.0865245"));
    	i.putExtra("title", ((MovieClip)getListAdapter().getItem(position)).getTitle());
    	i.putExtra("category_tags", ((MovieClip)getListAdapter().getItem(position)).getCategory()+";"+((MovieClip)getListAdapter().getItem(position)).getTags());    	
    	i.putExtra("app_activity_time", "");
    	i.putExtra("app_activity", "tests");
    	i.putExtra("position", position);
    	i.putExtra("videoLength", ((MovieClip)getListAdapter().getItem(position)).getDuration().toString());
    	this.startActivity(i);   
    	
//		ListOfMovies.add(
//				new MovieClip(	"silly comedy",
//								Integer.valueOf(253),
//								"rtsp://v5.cache1.c.youtube.com/CjcLENy73wIaLgn8FhPBKxSVxBMYDSANFEITVUdlbnQtWW91VHViZURlbW8tMUgGUgZ2aWRlb3MM/0/0/0/video.3gp",
//								"http://www.youtube.com/v/xJUUK8ETFvw?f=videos&c=UGent-YouTubeDemo-1&app=youtube_gdata","" +
//								"rtsp://v2.cache8.c.youtube.com/CjcLENy73wIaLgn8FhPBKxSVxBMYESARFEITVUdlbnQtWW91VHViZURlbW8tMUgGUgZ2aWRlb3MM/0/0/0/video.3gp",
//								"Mr  Bean went to the swimming pool",
//								Float.valueOf("0.0"),
//								"http://i.ytimg.com/vi/xJUUK8ETFvw/2.jpg",
//								"http://www.youtube.com/v/xJUUK8ETFvw",
//								Integer.valueOf(71),
//								"Comedy",
//								Float.valueOf("3.0865245"),
//								"",
//								"Mr Bean wemt to the swimming pool"));

    	
    	
    	
    	//    	Log.v(LOG_TAG, LOG_TAG2+Uri.parse(((MovieClip)getListAdapter().getItem(position)).getFormat1()));
    	//    	Log.v(LOG_TAG, LOG_TAG2+((MovieClip)getListAdapter().getItem(position)).getUrl());
    	//    	Log.v(LOG_TAG, LOG_TAG2+((MovieClip)getListAdapter().getItem(position)).getURLThumbnail());
    	//    	Log.v(LOG_TAG, LOG_TAG2+((MovieClip)getListAdapter().getItem(position)).getTotalRating());
    	//    	Log.v(LOG_TAG, LOG_TAG2+((MovieClip)getListAdapter().getItem(position)).getTitle());
    }//onListItemClick method
}
